#!/bin/zsh

# TARGETS
# Shows historical targets

USR=$1
EXERCISE=$2

set -eu

checkvars USR EXERCISE

[[ -d users/${USR} ]] || crash "No such user: ${USER}"

for PLAN in users/${USR}/plans/plan-*.txt
do
  NAME=${PLAN:t}
  [[ ${NAME} == plan-2012* ]] && continue
  [[ ${NAME} == plan-2013* ]] && continue
  if grep -q "\[${EXERCISE}\]" ${PLAN}
  then
    [[ ${NAME} =~ "plan-(.*).txt" ]]
    printf "${match} "
    grep "\[${EXERCISE}\].*target=.* " ${PLAN} | grep -o "target=.*"
  fi
done
